package com.spring.sunflower.conversation

import android.os.Bundle
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.spring.sunflower.R
import com.spring.sunflower.base.BaseCompatFragment
import com.spring.sunflower.bean.TalkRepositoryBean
import com.spring.sunflower.bottompanel.EmotionMainFragment
import java.io.Serializable

/**
 * Created by Kevin on 2021/7/30<br/>
 *
 * Describe:<br/>
 */
class TopicSubFragment : BaseCompatFragment() {
    private var recyclerView: RecyclerView? = null
    private var mData: MutableList<TalkRepositoryBean.DatasBean.ContentArrayBean> = ArrayList()
    private var topicContentAdapter: TopicContentAdapter? = null

    companion object {
        public fun newInstance(data: MutableList<TalkRepositoryBean.DatasBean.ContentArrayBean>): TopicSubFragment {
            var x = TopicSubFragment()
            val bundle = Bundle()
            bundle.putSerializable("content", data as Serializable)
            x.arguments = bundle
            return x;
        }
    }

    override fun setLayoutResId(): Int = R.layout.fragment_topic_sub

    override fun initView() {
        val data: MutableList<TalkRepositoryBean.DatasBean.ContentArrayBean> =
            arguments?.getSerializable("content") as MutableList<TalkRepositoryBean.DatasBean.ContentArrayBean>
        recyclerView = mView.findViewById(R.id.rvRecyclerView)
        val linearLayoutManager = LinearLayoutManager(mActivity)
        recyclerView!!.layoutManager = linearLayoutManager
        topicContentAdapter = TopicContentAdapter(R.layout.adapter_topic_content, data)
        recyclerView!!.adapter = topicContentAdapter!!
        topicContentAdapter?.setOnItemClickListener { adapter, view, position ->
            val content = data[position].content
            EmotionMainFragment.etEditInput.setText(
                content
            )
            EmotionMainFragment.etEditInput.setSelection(content.length)
        }
    }

    override fun initData() {
    }

    override fun initListener() {
    }

    override fun loadData() {
    }
}